function getJSONdata(pn){
	console.log(pn);
	$.ajax({
		url:"./data.json",
		type:"get",
		dataType:"json",
		success:function(data){
			console.log(data);
			if(data.code==0){
				var cardata = data.data;
				var index = Object.keys(cardata);
				var totalCount = index.length;//总记录数
				// console.log(totalCount);
				var pageSize = 5;//每页显示的记录数
				var pageTotal = Math.ceil(totalCount/pageSize);
				console.log(pageTotal);
				$(".total").html(pageTotal);

				var startPage = pageSize*(pn-1);
				var endPage = startPage+pageSize-1;

				var $div= $("#content");
				$div.empty();
				for(i=0;i<pageSize;i++){
					$div.append("<ul class='contentul'></ul>");
				}

				if(pageTotal==1){
					for(var j=0;j<totalCount;j++){
						$(".contentul").eq(j).append("<li style='width:4%''><input type='checkbox' class='btfxk'></li>")
						.append("<li style='width:12%'><span>"+cardata[index[j]].chepai+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].chejia+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].shebeihao+"</span></li>")
						.append("<li style='width:8%'><span>"+cardata[index[j]].gonggaohao+"</span></li>")
						.append("<li style='width:8%'><span>"+cardata[index[j]].chedui+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].time+"</span></li>")
						.append("<li style='width:12%''><span><input type='button' value='在线'></span></li>")
					}
				}else{
					for(var j=startPage,k=0;j<endPage,k<pageSize;j++,k++){
						if(j==totalCount){
							break;//当遍历到最后一条记录时跳出循环
						}
						$(".contentul").eq(k).append("<li style='width:4%''><input type='checkbox' class='btfxk'></li>")
						.append("<li style='width:12%'><span>"+cardata[index[j]].chepai+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].chejia+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].shebeihao+"</span></li>")
						.append("<li style='width:8%'><span>"+cardata[index[j]].gonggaohao+"</span></li>")
						.append("<li style='width:8%'><span>"+cardata[index[j]].chedui+"</span></li>")
						.append("<li style='width:14%'><span>"+cardata[index[j]].time+"</span></li>")
						// .append("<li style='width:12%''><span><input type='button' value='在线'></span></li>");
						if(cardata[index[j]].cheliangstatus==1){
							$(".contentul").eq(k).append("<li style='width:12%''><span><input type='button' value='在线'></span></li>")
						}else if(cardata[index[j]].cheliangstatus==0){
							$(".contentul").eq(k).append("<li style='width:12%''><span><input type='button' value='离线' class='lixian'></span></li>")
						}else{
							$(".contentul").eq(k).append("<li style='width:12%''><span><input type='button' value='故障' class='guzhang'></span></li>")
						}

					}
				}
			}
		}
	})
}

function getPage(){
	$.ajax({
		url:"./data.json",
		type:"get",
		dataType:"json",
		success:function(data){
			if(data.code==0){
				pn=1;
				var cardata = data.data;

				var index = Object.keys(cardata);
				var totalCount = index.length;//总记录数
				// console.log(totalCount);
				var pageSize = 5;//每页显示的记录数
				var pageTotal = Math.ceil(totalCount/pageSize);//总页数

				$("#next").click(function(){
					if(pn==pageTotal){
						alert("后面没有了");
						pn=pageTotal;
					}else{
						pn++;
						gotoPage(pn);
					}
				});

				$("#before").click(function(){
					if(pn==1){
						alert("前面没有了");
						pn=1;
					}else{
						pn--;
						gotoPage(pn);
					}
				});

				$("#firstPage").click(function(){
					console.log("aa");
					pn=1;
					gotoPage(pn);
					showMessage("已经是首页了");

				});

				$("#lastPage").click(function(){
					pn=pageTotal;
					gotoPage(pn);
				})

				$("#firstPage").trigger('click');

				$("#jumpPage").click(function(){
					console.log($("#inputNumber").val());
					pn = $("#inputNumber").val();
					gotoPage(pn);
				})
			}
		}
	})
}

function gotoPage(pn){
	$("#inputNumber").val(pn);
	getJSONdata(pn);
}

$(function(){
	getPage();

		$("#lichengcontainer").highcharts({
				chart:{
					type:"column"
				},
				title:{
					text:"里程统计 单位km"
				},
				xAxis:{
					categories:["24.1","25.1","26.1","27.1"],
					crosshair:true
				},
				yAxis:{
					allowDecimals:false,
					min:0,
					title:{
						text:"licheng"
					}
				},
				tooltip:{
					formatter:function(){
						return "<b>"+this.series.name+'</b><br>'+
						this.point.y;
					}
				},
				series:[{
					name:"总里程",
					data:[20,30,100,22,11,24]
				},{
					name:"新增里程",
					data:[10,20,30,10,20,10]
				}]

			})
})